﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.WebProvider
@{
    ViewBag.Title = "销售机构列表";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
@model ZBJF.Warranty.Model.SellersOrganization
@{
    var result = ServiceFactory.SellersOrganizationServiceInstance.GetSellersOrganizationAll().OrderBy(o => o.Sort).ToList();
}
<div class="main-content">
    <div class="breadcrumbs" id="breadcrumbs">
        <ul class="nav nav-tabs">
            <li class="active">
                <a href="/SellersOrganization/">
                    销售机构列表
                </a>
            </li>
        </ul>
    </div>
    <div class="page-content">
        <div class="widget-main">
            <label class="Add-R">
                <a id="AddNewRole" class="btn btn-xs btn-primary" data-toggle="modal" href="" onclick="showAddNewAdmin()" title=" 添加新销售机构">
                    <i class="icon-plus-sign bigger-130"></i>
                    添加新销售机构
                </a>
            </label>
            <div class="table-responsive">
                <div class="table_top"></div>
                <div class="categoryTree">
                    <table class="table table-striped table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>销售机构名称</th>
                                <th>销售商类型</th>
                                <th>是否显示</th>
                                <th>创建时间</th>
                                <th>排序</th>
                                <th>管理操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @Html.Action("ShowMenuList", "SellersOrganization", new { listPage = result, pid = 0, layer = 0 })
                        </tbody>
                    </table>
                </div>
                <div class="table_bottom"></div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="ShowAdd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    @RenderPage("DisplayTemplates/SellersOrganizationForm.cshtml", new { ItemList = result })
</div>
@section scripts{
    @Scripts.Render("~/bundles/chosen")
    @Scripts.Render("~/bundles/permission")
    <script type="text/javascript">
        function showAddNewAdmin() {
            document.getElementById("mvcForm").reset(); //清空表单
            $("#ID").val(0);
            $('#ShowAdd').modal();
        }

        function ShowEidtDialog(id) {
            clearForm("mvcForm");
            $.ajax({
                type: "post",
                data: { id: id },
                url: "/SellersOrganization/GetSellersOrganizationInfo",
                success: function (result) {
                    if (result.success) {
                        $("#ID").val(id);
                        $("#OrganizationName").val(result.result.OrganizationName);
                        $("#ParentOrganizationId option[value='" + result.result.ParentOrganizationId + "']").attr("selected", "selected");
                        $("#SellerType option[value='" + result.result.SellerType + "']").attr("selected", "selected");
                        if (result.result.IsAvailable) {
                            $("input[name='IsAvailable']").eq(1).removeAttr("checked");
                            $("input[name='IsAvailable']").eq(0).attr("checked", "checked");
                        } else {
                            $("input[name='IsAvailable']").eq(1).attr("checked", "checked");
                            $("input[name='IsAvailable']").eq(0).removeAttr("checked");
                        }
                        $("#Sort").val(result.result.Sort);
                        //$("#PidSelect").html($("#ParentOrganizationId"));
                        //$("#ParentOrganizationId").chosen();;
                        $('#ShowAdd').modal();
                    } else {
                        layer.alert(result.message);
                    }
                },
                error: function (error) {
                    console.log(error.responseText);
                }
            });
        }
    </script>
}